<?php


namespace App\Models\Garbage;
use App\Models\CarModels\CarArea;
use App\Models\SystemManagement\Employee;
use App\Models\SystemManagement\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Facade;
use DB;
class GarbageEvent extends Model
{

    protected $table = 'garbage_events';
    protected $fillable = ['title','desc','user_id','admin_id','area_id','address','status','reward','reward_type',
        'is_reward','anonymous','is_recall'];

    public function user(){
        return $this->belongsTo(WeichatUser::class,'user_id','id');

    }
    public function admin(){
        return $this->belongsTo(Employee::class,'admin_id','id');
    }

    public function area(){
        return $this->belongsTo(CarArea::class,'area_id','id')->with('city');
    }

    public function images(){
        return $this->hasMany(GarbageEventFiles::class,'event_id')->with('files');
    }

    public function singleFile(){
        //返回三个 图片 音频 视频中的各一个
        $data = $this->hasMany(GarbageEventFiles::class,'event_id')->with('file');

        //select * from `hw_garbage_event_files` where id in (select max(id) from `file_upload` GROUP BY `type`)
        return $data;
    }



}